<?php

namespace app\common\behavior;


use think\Exception;
use think\exception\ValidateException;

class JuheSms
{
    protected $sendUrl = 'http://v.juhe.cn/sms/send';
    protected $key = 'a5f99badbbf4870bbf9cabb4d5db29da';
    protected $tpl_id_single;
    public function __construct() {
        $this->key = config('site.juhe_key');
        $this->tpl_id_single = config('site.tpl_id_single');
    }

    public function smsSend($sms) {
        $smsConf = array(
            'key'   => $this->key, //您申请的APPKEY
            'mobile'    => $sms['mobile'], //接受短信的用户手机号码
            'tpl_id'    => $this->tpl_id_single, //您申请的短信模板ID，根据实际情况修改
            'tpl_value' =>'#code#='.$sms['code'] //您设置的模板变量，根据实际情况修改
        );

        $content = $this->juhecurl($this->sendUrl,$smsConf,1); //请求发送短信
        if($content){
            $result = json_decode($content,true);
            $error_code = $result['error_code'];
            if($error_code == 0){
                //状态为0，说明短信发送成功
                return true;
            }else{
                //状态非0，说明失败
                return false;
            }
        }else{
            //返回内容异常，以下可根据业务逻辑自行修改
            return false;
        }
    }


}
